
#ifndef MATRIX_H_
#define MATRIX_H_

#include "../library.h"
#include <ostream>

using namespace std;

class Matrix4f {
public:
	Matrix4f() {
		for(unsigned i=0; i<16; ++i) {
			m[i] = 0;
		}
		m[0] = 1;
		m[5] = 1;
		m[10] = 1;
		m[15] = 1;
	}

	Matrix4f(const GLfloat mat[16]) {
		for(unsigned i=0; i<16; ++i) {
			m[i] = mat[i];
		}
	}

	void glMult() {
		glMultMatrixf(m);
	}

	Matrix4f operator*(Matrix4f mat) {
		Matrix4f res;
		for(unsigned i=0; i<4; ++i) {
			for(unsigned j=0; j<4; ++j) {
				res.m[i*4 + j] = 0;
				for(unsigned k=0; k<4; ++k) {
					res.m[i*4 + j] += m[i*4 + k] * mat.m[k*4 + j];
				}
			}
		}
		return res;
	}

	GLfloat get(unsigned i, unsigned j) {
		return m[i*4 + j];
	}

	friend ostream& operator<<(ostream& os, const Matrix4f& mat);

private:
	GLfloat m[16];
};

ostream& operator<<(ostream& os, const Matrix4f& mat) {
	for(unsigned i=0; i<4; ++i) {
		for(unsigned j=0; j<4; ++j) {
			os << mat.m[i*4 + j] << "\t";
		}
		os << endl;
	}
	return os;
}

#endif /* MATRIX_H_ */
